class Solution
{
public:
    int longestAwesome(string s)
    {
        int mask = 0;
        unordered_map<int, int> m;
        m[0] = -1;
        int result = 0;
        for (int i = 0; i < s.size(); ++i)
        {
            mask ^= 1 << (s[i] - '0');

            if (m.count(mask))
            {
                result = max(result, i - m[mask]);
            }
            else
            {
                m[mask] = i;
            }

            for (int diff = 0; diff < 10; ++diff)
            {
                int diffMask = mask ^ (1 << diff);
                if (m.count(diffMask))
                {
                    result = max(result, i - m[diffMask]);
                }
            }
        }
        return result;
    }
};